/*
 * 作者:熊猫
 * 日期:2017 - 3 - 19 10 - 46 - 37
 *
 */

package net.lainiao.other.CodeStatic;

import org.omg.CORBA.Environment;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;

/**
 * Created by Administrator on 2017/3/19.
 */
public class Main {
    public static void main(String[] args) {
        ForkJoinPool pool=new ForkJoinPool();
        File file=new File("./");
        CodeTask codeTask=new CodeTask(file);
        pool.invoke(codeTask);
        pool.shutdown();
        try {
            int res=codeTask.get();
            File codeFile=new File(file,"CodeSearch0Doc/codeFile.md");
            if(!codeFile.exists()){
                try {
                    codeFile.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {
                RandomAccessFile randomFile=new RandomAccessFile(codeFile,"rw");
                long fileLength=randomFile.length();
                randomFile.seek(fileLength);
                SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date now=new Date();
                String lineSeparator = System.getProperty("line.separator", "\n");
                String appendStr= format.format(now)+" Code For Count: "+res+lineSeparator;
                randomFile.writeBytes(appendStr);
                randomFile.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("Main Code Line Counter "+res);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
